package com.bosssoft.trainee.nontax.service.impl;

import com.bosssoft.trainee.nontax.dao.ResourceDao;
import com.bosssoft.trainee.nontax.service.ResourceService;
import com.bosssoft.trainee.nontax.entity.dto.ResourceDto;
import com.bosssoft.trainee.nontax.entity.vo.ResourceVo;
import com.bosssoft.trainee.nontax.util.mapper.dtoVo.ResourceDtoVo;
import com.bosssoft.trainee.nontax.util.mapper.poDto.ResourcePoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Description: (Resource)表服务实现类
 * @Author: Luo WenLong
 * @since 2022-06-12 10:16:13
 */
@Service("resourceService")
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private ResourceDao resourceDao;

    @Autowired
    ResourceDtoVo resourceDtoVo;

    @Autowired
    ResourcePoDto resourcePoDto;

    /**
     * @Description: 通过ID查询单条数据
     * @param resourceId 主键
     * @return 实例对象
     */
    @Override
    public ResourceVo queryById(Integer resourceId) {
        return resourceDtoVo.dto2vo(resourcePoDto.po2dto(this.resourceDao.queryById(resourceId)));
    }

    /**
     * @Description: 新增数据
     * @param resource 实例对象
     * @return 实例对象
     */
    @Override
    public ResourceVo insert(ResourceDto resource) {
        this.resourceDao.insert(resource);
        return resourceDtoVo.dto2vo(resource);
    }

    /**
     * @Description: 修改数据
     * @param resource 实例对象
     * @return 实例对象
     */
    @Override
    public ResourceVo update(ResourceDto resource) {
        this.resourceDao.update(resource);
        return this.queryById(resource.getResourceId());
    }

    /**
     * @Description: 通过主键删除数据
     * @param resourceId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer resourceId) {
        return this.resourceDao.deleteById(resourceId) > 0;
    }
}
